﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace WebUI.Controllers
{
    public class BlankController : Controller
    {
        //
        // GET: /Blank/
        public class Message
        {
            /// <summary>
            /// 拼接消息提示
            /// </summary>
            /// <param name="width">提示的消息页面宽度</param>
            /// <param name="head">是否有标题</param>
            /// <param name="headtitle">标题内容，若为空，则显示“提示”</param>
            /// <param name="content">消息内容</param>
            /// <returns></returns>
            public static string BuildMessage(int width, bool head, string headtitle, string content)
            {
                StringBuilder mes = new StringBuilder();
                if (headtitle == "") headtitle = "提示";
                mes.AppendFormat("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"MessageBox\" align=\"center\" width=\"" + width + "\">");
                if (!head)
                {
                    mes.AppendFormat("<tr class=\"head-no-title\">");
                    mes.AppendFormat("<td class=\"left\"></td>");
                    mes.AppendFormat("<td class=\"center\"></td>");
                    mes.AppendFormat("<td class=\"right\"></td>");
                    mes.AppendFormat("</tr>");
                }
                else
                {
                    mes.AppendFormat("<tr class=\"head\">");
                    mes.AppendFormat("<td class=\"left\"></td>");
                    mes.AppendFormat("<td class=\"center\">");
                    mes.AppendFormat("<div class=\"title\">" + headtitle + "</div>");
                    mes.AppendFormat("</td>");
                    mes.AppendFormat("<td class=\"right\"></td>");
                    mes.AppendFormat("</tr>");
                }
                mes.AppendFormat("<tr class=\"msg\">");
                mes.AppendFormat("<td class=\"left\"></td>");
                mes.AppendFormat("<td class=\"center info\">");
                mes.AppendFormat("<div class=\"msg-content\">" + content + "</div>");
                mes.AppendFormat("</td>");
                mes.AppendFormat("<td class=\"right\"></td>");
                mes.AppendFormat("</tr>");
                mes.AppendFormat("<tr class=\"foot\">");
                mes.AppendFormat("<td class=\"left\"></td>");
                mes.AppendFormat("<td class=\"center\"></td>");
                mes.AppendFormat("<td class=\"right\"></td>");
                mes.AppendFormat("<tr>");
                mes.AppendFormat("</table>");
                return mes.ToString();
            }

        }
        #region 页面

        /// <summary>
        /// 空白页
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public ActionResult Index(string msg, bool part = true)
        {
            ViewBag.Msg = Server.UrlDecode(msg);
            if (part)
            {
                return PartialView();
            }
            else
            {
                return View();
            }
        }

        /// <summary>
        /// 空白的tab页
        /// </summary>
        /// <returns></returns>
        public ActionResult BlankTab()
        {
            return PartialView();
        }

        /// <summary>
        /// 空白的panel页
        /// </summary>
        /// <returns></returns>
        public ActionResult BlankPanel()
        {
            return PartialView();
        }

        #endregion
        #region 其他

        /// <summary>
        /// 获取消息HTML代码
        /// </summary>
        /// <param name="msg">提示内容</param>
        /// <returns></returns>
        [HttpPost]
        public string Msage(string msg)
        {
            return Message.BuildMessage(400, true, "", msg);
        }

        /// <summary>
        /// 获取消息HTML代码
        /// </summary>
        /// <param name="width">宽度</param>
        /// <param name="msg">提示内容</param>
        /// <returns></returns>
        [HttpPost]
        public string Msage1(int width, string msg)
        {
            return Message.BuildMessage(width, true, "", msg);
        }

        #endregion
        
    }
}
